package com.briup.cms.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.cms.bean.Slideshow;
import com.briup.cms.service.ISlideshowService;
import com.briup.cms.util.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author briup
 * @program: 230307-CMS
 * @description 轮播图控制器类
 **/
@Slf4j
@Api(tags = "轮播图模块")
@RestController
@RequestMapping("/slideshow")
public class SlideshowController {
    @Autowired
    private ISlideshowService slideshowService;

    @ApiOperation(value = "根据id查询轮播图信息", notes = "用于更新时的数据回显")
    @GetMapping("/queryById/{id}")
    public Result getById(@PathVariable Integer id) {
        System.out.println("id: " + id);

        Slideshow slideshow = slideshowService.queryById(id);
        System.out.println("find: " + slideshow);

        return Result.success(slideshow);
    }

    @ApiOperation(value = "查询所有启用的轮播图信息")
    @GetMapping("/queryAllEnable")
    public Result queryAllEnable() {
        List<Slideshow> slideshows = slideshowService.queryAllEnable();
        return Result.success(slideshows);
    }

    @ApiOperation("查询所有轮播图")
    @GetMapping("/query")
    public Result query(Integer pageNum, Integer pageSize, String status, String description) {
        Page<Slideshow> slideshows = slideshowService.queryAll(pageNum, pageSize, status, description);
        return Result.success(slideshows);
    }

    @ApiOperation(value = "新增或更新轮播图", notes = "slideshow参数包含 id值则为更新，不包含i为新增")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Slideshow slideshow) {
        slideshowService.saveOrUpdate(slideshow);
        return Result.success("操作成功");
    }
    @ApiOperation(value = "批量删除轮播图", notes = "需要提供多个id值")
    @DeleteMapping("/deleteByBatch/{ids}")
    public Result deleteSlideshowInBatch(@PathVariable("ids") List<Integer> ids) {
        log.info("ids: {}",ids);
        slideshowService.deleteInBatch(ids);
        return Result.success("删除成功");
    }

}
